#stat -c "%i %h" "$f"|read inode hardlinks #separate process, won't work
function recursive {
	pushd "$1">/dev/null
	RETVAL=$?
	if [ $RETVAL -ne 0 ]; then
		echo Was in `pwd`>&2
		return $RETVAL
	else
		local f
		for f in *; do
			if [ -f "$f" -a -O "$f" ]; then
				local hardlinks=$(stat -c %h "$f")
				if [ $hardlinks -gt 1 ]; then
					if [ ! -w . ]; then
						#let's assume we're the owner
						chmod +w .
					fi
					echo rm "$f"
					rm "$f"
				fi
			elif [ -d "$f" ]; then
				recursive "$f"
			fi
		done
		popd>/dev/null
		return 0
	fi
}
if [ "$1" ]; then
	set -u #error when using undeclared variables
	recursive "$1"
else
	echo "Usage: `basename "$0"` target"
fi
